﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OShiYuanReportListHighcharts : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "OShiYuanReportList";
            }
        }
        /// <summary>
        /// 上一年
        /// </summary>
        protected int PreYear
        {
            get
            {
                return Year - 1;
            }
        }

        protected int Year
        {
            get
            {
                return GetRequestValue<int>("year", DateTime.Now.Year);
            }
        }
        protected int Month
        {
            get
            {
                return GetRequestValue<int>("Month", DateTime.Now.Month);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                GridView1.DataSource = GetReport1ShowData();
                GridView1.DataBind();

                GridView2.DataSource = GetReport2ShowData();
                GridView2.DataBind();

                GridView3.DataSource = GetReport3ShowData();
                GridView3.DataBind();

                GridView4.DataSource = GetReport4ShowData();
                GridView4.DataBind();
            }
            catch
            { }
        }

       

        private DataTable _PreYearShiYuanReportDT = null;
        /// <summary>
        /// 上一年市怨/厂异月度走势数据
        /// </summary>
        private DataTable PreYearShiYuanReportDT
        {
            get
            {
                if (_PreYearShiYuanReportDT == null)
                {
                    _PreYearShiYuanReportDT = OShiYuanReportController.OShiYuanReport_GetData(PreYear);
                }
                return _PreYearShiYuanReportDT;
            }
        }

        private DataTable _YearShiYuanReportDT = null;
        /// <summary>
        /// 今年市怨/厂异月度走势数据
        /// </summary>
        private DataTable YearShiYuanReportDT
        {
            get
            {
                if (_YearShiYuanReportDT == null)
                {
                    _YearShiYuanReportDT = OShiYuanReportController.OShiYuanReport_GetData(Year);
                }
                return _YearShiYuanReportDT;
            }
        }

        private DataTable _MonthTopReportDT = null;
        /// <summary>
        /// 今年月份市怨前10大分类及厂异前10大供应商数量
        /// </summary>
        private DataTable MonthTopReportDT
        {
            get
            {
                if (_MonthTopReportDT == null)
                {
                    _MonthTopReportDT = OShiYuanReportController.OShiYuanMonthTopReport_GetData(Year,Month);
                }
                return _MonthTopReportDT;
            }
        }

        

        #region 报表1
        protected string GetReport1Series()
        { 
            /*
             {
                            name: '11年市怨件数',
                            type: 'column',
                            yAxis: 0,
                            data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

                        },
             */
            StringBuilder sb = new StringBuilder();
            //1.上一年市怨件数
            DataRow dr = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "市怨件"))[0];           
            sb.Append("{");
            sb.AppendFormat("name: '{0}年市怨件数',",PreYear);
            sb.Append("type: 'column',");
            sb.Append("yAxis: 0,");
            sb.Append("data:[");
            sb.AppendFormat("{0},", dr["Month1"]);
            sb.AppendFormat("{0},", dr["Month2"]);
            sb.AppendFormat("{0},", dr["Month3"]);
            sb.AppendFormat("{0},", dr["Month4"]);
            sb.AppendFormat("{0},", dr["Month5"]);
            sb.AppendFormat("{0},", dr["Month6"]);
            sb.AppendFormat("{0},", dr["Month7"]);
            sb.AppendFormat("{0},", dr["Month8"]);
            sb.AppendFormat("{0},", dr["Month9"]);
            sb.AppendFormat("{0},", dr["Month10"]);
            sb.AppendFormat("{0},", dr["Month11"]);
            sb.AppendFormat("{0}", dr["Month12"]);
            sb.Append("]");
            sb.Append("},");
            //2.本年市怨件
            dr = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "市怨件"))[0];
            sb.Append("{");
            sb.AppendFormat("name: '{0}年市怨件数',", Year);
            sb.Append("type: 'column',");
            sb.Append("yAxis:0,");
            sb.Append("data:[");
            sb.AppendFormat("{0},", dr["Month1"]);
            sb.AppendFormat("{0},", dr["Month2"]);
            sb.AppendFormat("{0},", dr["Month3"]);
            sb.AppendFormat("{0},", dr["Month4"]);
            sb.AppendFormat("{0},", dr["Month5"]);
            sb.AppendFormat("{0},", dr["Month6"]);
            sb.AppendFormat("{0},", dr["Month7"]);
            sb.AppendFormat("{0},", dr["Month8"]);
            sb.AppendFormat("{0},", dr["Month9"]);
            sb.AppendFormat("{0},", dr["Month10"]);
            sb.AppendFormat("{0},", dr["Month11"]);
            sb.AppendFormat("{0}", dr["Month12"]);
            sb.Append("]");
            sb.Append("},");

            //3.上一年市怨百分比
            DataRow drBYL = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "保有量"))[0];
            DataRow drSYJ = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "市怨件"))[0];
            sb.Append("{");
            sb.AppendFormat("name: '{0}年市怨百分比',", PreYear);
            sb.Append("type: 'spline',");
            sb.Append("yAxis: 1,");
            sb.Append("dashStyle: 'shortdot',");
            sb.Append("data:[");
            sb.AppendFormat("{0}", GetPre(drSYJ["Month1"], drBYL["Month1"]) == "0" ? "" : string.Format("[0,{0}]", GetPre(drSYJ["Month1"], drBYL["Month1"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month2"], drBYL["Month2"]) == "0" ? "" : string.Format(",[1,{0}]", GetPre(drSYJ["Month2"], drBYL["Month2"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month3"], drBYL["Month3"]) == "0" ? "" : string.Format(",[2,{0}]", GetPre(drSYJ["Month3"], drBYL["Month3"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month4"], drBYL["Month4"]) == "0" ? "" : string.Format(",[3,{0}]", GetPre(drSYJ["Month4"], drBYL["Month4"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month5"], drBYL["Month5"]) == "0" ? "" : string.Format(",[4,{0}]", GetPre(drSYJ["Month5"], drBYL["Month5"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month6"], drBYL["Month6"]) == "0" ? "" : string.Format(",[5,{0}]", GetPre(drSYJ["Month6"], drBYL["Month6"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month7"], drBYL["Month7"]) == "0" ? "" : string.Format(",[6,{0}]", GetPre(drSYJ["Month7"], drBYL["Month7"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month8"], drBYL["Month8"]) == "0" ? "" : string.Format(",[7,{0}]", GetPre(drSYJ["Month8"], drBYL["Month8"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month9"], drBYL["Month9"]) == "0" ? "" : string.Format(",[8,{0}]", GetPre(drSYJ["Month9"], drBYL["Month9"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month10"], drBYL["Month10"]) == "0" ? "" : string.Format(",[9,{0}]", GetPre(drSYJ["Month10"], drBYL["Month10"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month11"], drBYL["Month11"]) == "0" ? "" : string.Format(",[10,{0}]", GetPre(drSYJ["Month11"], drBYL["Month11"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month12"], drBYL["Month12"]) == "0" ? "" : string.Format(",[11,{0}]", GetPre(drSYJ["Month12"], drBYL["Month12"])));
            sb.Append("]");
            sb.Append("},");
            //4.今年市怨百分比

            drBYL = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "保有量"))[0];
            drSYJ = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "市怨件"))[0];
            sb.Append("{");
            sb.AppendFormat("name: '{0}年市怨百分比',", Year);
            sb.Append("type: 'spline',");
            sb.Append("yAxis: 1,");
            sb.Append("data:[");
            sb.AppendFormat("{0}", GetPre(drSYJ["Month1"], drBYL["Month1"]) == "0" ? "" : string.Format("[0,{0}]", GetPre(drSYJ["Month1"], drBYL["Month1"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month2"], drBYL["Month2"]) == "0" ? "" : string.Format(",[1,{0}]", GetPre(drSYJ["Month2"], drBYL["Month2"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month3"], drBYL["Month3"]) == "0" ? "" : string.Format(",[2,{0}]", GetPre(drSYJ["Month3"], drBYL["Month3"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month4"], drBYL["Month4"]) == "0" ? "" : string.Format(",[3,{0}]", GetPre(drSYJ["Month4"], drBYL["Month4"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month5"], drBYL["Month5"]) == "0" ? "" : string.Format(",[4,{0}]", GetPre(drSYJ["Month5"], drBYL["Month5"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month6"], drBYL["Month6"]) == "0" ? "" : string.Format(",[5,{0}]", GetPre(drSYJ["Month6"], drBYL["Month6"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month7"], drBYL["Month7"]) == "0" ? "" : string.Format(",[6,{0}]", GetPre(drSYJ["Month7"], drBYL["Month7"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month8"], drBYL["Month8"]) == "0" ? "" : string.Format(",[7,{0}]", GetPre(drSYJ["Month8"], drBYL["Month8"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month9"], drBYL["Month9"]) == "0" ? "" : string.Format(",[8,{0}]", GetPre(drSYJ["Month9"], drBYL["Month9"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month10"], drBYL["Month10"]) == "0" ? "" : string.Format(",[9,{0}]", GetPre(drSYJ["Month10"], drBYL["Month10"])));
            sb.AppendFormat("{0}", GetPre(drSYJ["Month11"], drBYL["Month11"]) == "0" ? "" : string.Format(",[10,{0}]", GetPre(drSYJ["Month11"], drBYL["Month11"])));
            sb.AppendFormat("{0}",  GetPre(drSYJ["Month12"], drBYL["Month12"]) == "0" ? "" : string.Format(",[11,{0}]", GetPre(drSYJ["Month12"], drBYL["Month12"])));
            sb.Append("]");
            sb.Append("}");

            return sb.ToString();
        }

        protected string GetTooltipUnit()
        {
            /*
                var unit = {
                                '市怨件数': '件',
                                '市怨百分比': '%'
                            }[this.series.name];
             */
            StringBuilder sb = new StringBuilder();
            sb.Append("var unit = {");
            sb.AppendFormat(" '{0}年市怨件数': '件',", PreYear);
            sb.AppendFormat(" '{0}年市怨件数': '件',", Year);
            sb.AppendFormat(" '{0}年市怨百分比': '%',", PreYear);
            sb.AppendFormat(" '{0}年市怨百分比': '%'", Year);
            sb.Append("}[this.series.name]");

            return sb.ToString();
        }

        private string GetPre(object NUM1, object NUM2)
        {
            if (Convert.ToInt32(NUM1) == 0 || Convert.ToInt32(NUM2) == 0)
                return "0";

            return ((Convert.ToDecimal(NUM1) / Convert.ToDecimal(NUM2))*100).ToString("F1");
        }

        protected DataTable GetReport1ShowData()
        {
            DataTable showDT = new DataTable();

            DataColumn showDC = new DataColumn("月份");
            showDT.Columns.Add(showDC);
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                showDC = new DataColumn(monthIndex.ToString()+"月");
                showDT.Columns.Add(showDC);
            }
            showDC = new DataColumn("合计");
            showDT.Columns.Add(showDC);
            showDC = new DataColumn("月均");
            showDT.Columns.Add(showDC);

            int hjNum = 0;
            int hasMonthNum = 0;//只有数据大于0的月份才能进入月均计算
            int HJBYL=0;//合计保有量
            int HJSYJ=0;//合计市怨件
            int HJMonthBYL=0;//合计月均保有量
            int HJMonthSYJ=0;//合计月均市怨件
            DataRow showDR = showDT.NewRow();
            //1.上一年保有量           
            DataRow drBYL = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "保有量"))[0];                     
            showDR["月份"] = PreYear.ToString() + "年保修期内保有量";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                hjNum += Convert.ToInt32(drBYL["month" + monthIndex.ToString()]);
                showDR[monthIndex.ToString() + "月"] = drBYL["month" + monthIndex.ToString()];
                hasMonthNum += Convert.ToInt32(drBYL["month" + monthIndex.ToString()]) > 0 ? 1 : 0;
            }
            HJBYL=hjNum;
            showDR["合计"] = hjNum;
            HJMonthBYL=Convert.ToInt32(hjNum / hasMonthNum);
            showDR["月均"] =  (hjNum / hasMonthNum).ToString("F0");
            showDT.Rows.Add(showDR);
            //2.上一年市怨件
            showDR = showDT.NewRow();
            DataRow drSYJ = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "市怨件"))[0];
            hjNum = 0;
            hasMonthNum = 0;
            showDR["月份"] = PreYear.ToString() + "年市怨件数";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                hjNum += Convert.ToInt32(drSYJ["month" + monthIndex.ToString()]);
                showDR[monthIndex.ToString() + "月"] = drSYJ["month" + monthIndex.ToString()];
                hasMonthNum += Convert.ToInt32(drSYJ["month" + monthIndex.ToString()]) > 0 ? 1 : 0;
            }
            HJSYJ=hjNum;
            showDR["合计"] = hjNum;
            HJMonthSYJ=Convert.ToInt32(hjNum / hasMonthNum);
            showDR["月均"] = (hjNum / hasMonthNum).ToString("F0");
            showDT.Rows.Add(showDR);
            //3.上一年百份比
            showDR = showDT.NewRow();
            showDR["月份"] = PreYear.ToString() + "年百分比";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                showDR[monthIndex.ToString() + "月"] = GetPre(drSYJ["month" + monthIndex.ToString()], drBYL["month" + monthIndex.ToString()])+"%";
            }
            showDR["合计"] = GetPre(HJSYJ, HJBYL) + "%";
            showDR["月均"] = GetPre(HJMonthSYJ, HJMonthBYL) + "%";
            showDT.Rows.Add(showDR);

            //4.本年保有量
            showDR = showDT.NewRow();
            hjNum = 0;
            hasMonthNum = 0;
            drBYL = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "保有量"))[0];
            showDR["月份"] = Year.ToString() + "年保修期内保有量";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                hjNum += Convert.ToInt32(drBYL["month" + monthIndex.ToString()]);
                showDR[monthIndex.ToString() + "月"] = drBYL["month" + monthIndex.ToString()];
                hasMonthNum += Convert.ToInt32(drBYL["month" + monthIndex.ToString()]) > 0 ? 1 : 0;
            }
            HJBYL = hjNum;
            showDR["合计"] = hjNum;
            HJMonthBYL = Convert.ToInt32(hjNum / hasMonthNum);
            showDR["月均"] = (hjNum / hasMonthNum).ToString("F0");
            showDT.Rows.Add(showDR);
            //5.上一年市怨件
            showDR = showDT.NewRow();
            drSYJ = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "市怨件"))[0];
            hjNum = 0;
            hasMonthNum = 0;
            showDR["月份"] = Year.ToString() + "年市怨件数";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                hjNum += Convert.ToInt32(drSYJ["month" + monthIndex.ToString()]);
                showDR[monthIndex.ToString() + "月"] = drSYJ["month" + monthIndex.ToString()];
                hasMonthNum += Convert.ToInt32(drSYJ["month" + monthIndex.ToString()]) > 0 ? 1 : 0;
            }
            HJSYJ = hjNum;
            showDR["合计"] = hjNum;
            HJMonthSYJ = Convert.ToInt32(hjNum / hasMonthNum);
            showDR["月均"] = (hjNum / hasMonthNum).ToString("F0");
            showDT.Rows.Add(showDR);
            //6.年百份比
            showDR = showDT.NewRow();
            showDR["月份"] = Year.ToString() + "年百分比";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                showDR[monthIndex.ToString() + "月"] = GetPre(drSYJ["month" + monthIndex.ToString()], drBYL["month" + monthIndex.ToString()]) + "%";
            }
            showDR["合计"] = GetPre(HJSYJ, HJBYL) + "%";
            showDR["月均"] = GetPre(HJMonthSYJ, HJMonthBYL) + "%";
            showDT.Rows.Add(showDR);

            return showDT;
        }
        #endregion

        #region 报表2
        protected string GetReport2Categories()
        {
            DataTable dtcl = MonthTopReportDT.Select(string.Format("TopType='{0}'","市怨")).CopyToDataTable();
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            int rowindex = 1;
            foreach (DataRow dr in dtcl.Rows)
            {
                sb.AppendFormat("'{0}'", dr["ChangShang"]);
                if (rowindex != dtcl.Rows.Count)
                {
                    sb.AppendFormat(",");
                }
                rowindex++;
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            return filedstr;
        }

        protected string GetReport2Series()
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sbPre = new StringBuilder();

            int AllShuLiang = 0; //所有市怨件           
            DataTable dtcl = MonthTopReportDT.Select(string.Format("TopType='{0}'", "市怨")).CopyToDataTable();
            AllShuLiang=Convert.ToInt32( dtcl.Compute("sum(ShuLiang)", "1=1"));

            sb.Append("{");
            sb.Append("name: '市怨件数',");
            sb.Append("type: 'column',");
            sb.Append("yAxis: 0,");
            sb.Append("data:[");

            sbPre.Append("{");
            sbPre.Append("name: '百分比',");
            sbPre.Append("type: 'spline',");
            sbPre.Append("yAxis: 1,");
            sbPre.Append("dashStyle: 'shortdot',");
            sbPre.Append("data:[");

            int rowindex = 1;
            foreach (DataRow dr in dtcl.Rows)
            {
                sb.AppendFormat("{0}", dr["ShuLiang"]);
                sbPre.AppendFormat("{0}", GetPre(dr["ShuLiang"], AllShuLiang));
                if (rowindex != dtcl.Rows.Count)
                {
                    sb.AppendFormat(",");
                    sbPre.AppendFormat(",");
                }
                rowindex++;
            }

            sb.Append("]");
            sb.Append("},");

            sbPre.Append("]");
            sbPre.Append("}");

            return sb.ToString() + sbPre.ToString();
        }

        protected DataTable GetReport2ShowData()
        {
            DataTable showDT = new DataTable();
            DataTable dtcl = MonthTopReportDT.Select(string.Format("TopType='{0}'", "市怨")).CopyToDataTable();
            DataColumn showDC = new DataColumn("厂商");
            showDT.Columns.Add(showDC);
            foreach (DataRow dr in dtcl.Rows)
            {
                showDC = new DataColumn(dr["ChangShang"].ToString());
                showDT.Columns.Add(showDC);
            }
            showDC = new DataColumn("月合计");
            showDT.Columns.Add(showDC);


            int AllShuLiang = Convert.ToInt32(dtcl.Compute("sum(ShuLiang)", "1=1"));
            DataRow drSYJ = showDT.NewRow();
            DataRow drPRE = showDT.NewRow();
            drSYJ["厂商"] = "市怨件数";
            drPRE["厂商"] = "百分比";

            foreach (DataRow dr in dtcl.Rows)
            {
                drSYJ[dr["ChangShang"].ToString()] = dr["ShuLiang"].ToString();
                drPRE[dr["ChangShang"].ToString()] = GetPre(dr["ShuLiang"], AllShuLiang)+"%";
            }
            drSYJ["月合计"] = AllShuLiang;

            showDT.Rows.Add(drSYJ);
            showDT.Rows.Add(drPRE);

            return showDT;
        }
        #endregion

        #region 报表3
        protected string GetReport3Series()
        {
            /*
             {
                            name: '11年市怨件数',
                            type: 'column',
                            yAxis: 0,
                            data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

                        },
             */
            StringBuilder sb = new StringBuilder();
            //1.上一年异件数
            DataRow dr = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "异件数"))[0];
            sb.Append("{");
            sb.AppendFormat("name: '{0}年厂异件数',", PreYear);
            sb.Append("type: 'column',");
            sb.Append("yAxis: 0,");
            sb.Append("data:[");
            sb.AppendFormat("{0},", dr["Month1"]);
            sb.AppendFormat("{0},", dr["Month2"]);
            sb.AppendFormat("{0},", dr["Month3"]);
            sb.AppendFormat("{0},", dr["Month4"]);
            sb.AppendFormat("{0},", dr["Month5"]);
            sb.AppendFormat("{0},", dr["Month6"]);
            sb.AppendFormat("{0},", dr["Month7"]);
            sb.AppendFormat("{0},", dr["Month8"]);
            sb.AppendFormat("{0},", dr["Month9"]);
            sb.AppendFormat("{0},", dr["Month10"]);
            sb.AppendFormat("{0},", dr["Month11"]);
            sb.AppendFormat("{0}", dr["Month12"]);
            sb.Append("]");
            sb.Append("},");
            //2.本年异件数
            dr = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "异件数"))[0];
            sb.Append("{");
            sb.AppendFormat("name: '{0}年厂异件数',", Year);
            sb.Append("type: 'column',");
            sb.Append("yAxis:0,");
            sb.Append("data:[");
            sb.AppendFormat("{0},", dr["Month1"]);
            sb.AppendFormat("{0},", dr["Month2"]);
            sb.AppendFormat("{0},", dr["Month3"]);
            sb.AppendFormat("{0},", dr["Month4"]);
            sb.AppendFormat("{0},", dr["Month5"]);
            sb.AppendFormat("{0},", dr["Month6"]);
            sb.AppendFormat("{0},", dr["Month7"]);
            sb.AppendFormat("{0},", dr["Month8"]);
            sb.AppendFormat("{0},", dr["Month9"]);
            sb.AppendFormat("{0},", dr["Month10"]);
            sb.AppendFormat("{0},", dr["Month11"]);
            sb.AppendFormat("{0}", dr["Month12"]);
            sb.Append("]");
            sb.Append("},");

            //3.上一年百分比
            DataRow drJHS = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "交货数"))[0];
            DataRow drYJS = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "异件数"))[0];
            sb.Append("{");
            sb.AppendFormat("name: '{0}年百分比',", PreYear);
            sb.Append("type: 'spline',");
            sb.Append("yAxis: 1,");
            sb.Append("dashStyle: 'shortdot',");
            sb.Append("data:[");
          
            /**/

            sb.AppendFormat("{0}", GetPre(drYJS["Month1"], drJHS["Month1"]) == "0" ? "" : string.Format("[0,{0}]", GetPre(drYJS["Month1"], drJHS["Month1"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month2"], drJHS["Month2"]) == "0" ? "" : string.Format(",[1,{0}]", GetPre(drYJS["Month2"], drJHS["Month2"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month3"], drJHS["Month3"]) == "0" ? "" : string.Format(",[2,{0}]", GetPre(drYJS["Month3"], drJHS["Month3"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month4"], drJHS["Month4"]) == "0" ? "" : string.Format(",[3,{0}]", GetPre(drYJS["Month4"], drJHS["Month4"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month5"], drJHS["Month5"]) == "0" ? "" : string.Format(",[4,{0}]", GetPre(drYJS["Month5"], drJHS["Month5"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month6"], drJHS["Month6"]) == "0" ? "" : string.Format(",[5,{0}]", GetPre(drYJS["Month6"], drJHS["Month6"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month7"], drJHS["Month7"]) == "0" ? "" : string.Format(",[6,{0}]", GetPre(drYJS["Month7"], drJHS["Month7"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month8"], drJHS["Month8"]) == "0" ? "" : string.Format(",[7,{0}]", GetPre(drYJS["Month8"], drJHS["Month8"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month9"], drJHS["Month9"]) == "0" ? "" : string.Format(",[8,{0}]", GetPre(drYJS["Month9"], drJHS["Month9"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month10"], drJHS["Month10"]) == "0" ? "" : string.Format(",[9,{0}]", GetPre(drYJS["Month10"], drJHS["Month10"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month11"], drJHS["Month11"]) == "0" ? "" : string.Format(",[10,{0}]", GetPre(drYJS["Month11"], drJHS["Month11"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month12"], drJHS["Month12"]) == "0" ? "" : string.Format(",[11,{0}]", GetPre(drYJS["Month12"], drJHS["Month12"])));

            /**/
            sb.Append("]");
            sb.Append("},");
            //4.今年市怨百分比

            drJHS = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "交货数"))[0];
            drYJS = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "异件数"))[0];
            sb.Append("{");
            sb.AppendFormat("name: '{0}年百分比',", Year);
            sb.Append("type: 'spline',");
            sb.Append("yAxis: 1,");
            sb.Append("data:[");
            sb.AppendFormat("{0}", GetPre(drYJS["Month1"], drJHS["Month1"]) == "0" ? "" : string.Format("[0,{0}]", GetPre(drYJS["Month1"], drJHS["Month1"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month2"], drJHS["Month2"]) == "0" ? "" : string.Format(",[1,{0}]", GetPre(drYJS["Month2"], drJHS["Month2"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month3"], drJHS["Month3"]) == "0" ? "" : string.Format(",[2,{0}]", GetPre(drYJS["Month3"], drJHS["Month3"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month4"], drJHS["Month4"]) == "0" ? "" : string.Format(",[3,{0}]", GetPre(drYJS["Month4"], drJHS["Month4"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month5"], drJHS["Month5"]) == "0" ? "" : string.Format(",[4,{0}]", GetPre(drYJS["Month5"], drJHS["Month5"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month6"], drJHS["Month6"]) == "0" ? "" : string.Format(",[5,{0}]", GetPre(drYJS["Month6"], drJHS["Month6"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month7"], drJHS["Month7"]) == "0" ? "" : string.Format(",[6,{0}]", GetPre(drYJS["Month7"], drJHS["Month7"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month8"], drJHS["Month8"]) == "0" ? "" : string.Format(",[7,{0}]", GetPre(drYJS["Month8"], drJHS["Month8"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month9"], drJHS["Month9"]) == "0" ? "" : string.Format(",[8,{0}]", GetPre(drYJS["Month9"], drJHS["Month9"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month10"], drJHS["Month10"]) == "0" ? "" : string.Format(",[9,{0}]", GetPre(drYJS["Month10"], drJHS["Month10"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month11"], drJHS["Month11"]) == "0" ? "" : string.Format(",[10,{0}]", GetPre(drYJS["Month11"], drJHS["Month11"])));
            sb.AppendFormat("{0}", GetPre(drYJS["Month12"], drJHS["Month12"]) == "0" ? "" : string.Format(",[11,{0}]", GetPre(drYJS["Month12"], drJHS["Month12"])));
            sb.Append("]");
            sb.Append("}");

            return sb.ToString();
        }

        protected string GetTooltipUnit3()
        {
            /*
                var unit = {
                                '市怨件数': '件',
                                '市怨百分比': '%'
                            }[this.series.name];
             */
            StringBuilder sb = new StringBuilder();
            sb.Append("var unit = {");
            sb.AppendFormat(" '{0}年厂异件数': '件',", PreYear);
            sb.AppendFormat(" '{0}年厂异件数': '件',", Year);
            sb.AppendFormat(" '{0}年百分比': '%',", PreYear);
            sb.AppendFormat(" '{0}年百分比': '%'", Year);
            sb.Append("}[this.series.name]");

            return sb.ToString();
        }

      

        protected DataTable GetReport3ShowData()
        {
            DataTable showDT = new DataTable();

            DataColumn showDC = new DataColumn("月份");
            showDT.Columns.Add(showDC);
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                showDC = new DataColumn(monthIndex.ToString() + "月");
                showDT.Columns.Add(showDC);
            }
            showDC = new DataColumn("合计");
            showDT.Columns.Add(showDC);
            showDC = new DataColumn("月均");
            showDT.Columns.Add(showDC);

            int hjNum = 0;
            int hasMonthNum = 0;//只有数据大于0的月份才能进入月均计算
            int HJBYL = 0;//合计保有量
            int HJSYJ = 0;//合计市怨件
            int HJMonthBYL = 0;//合计月均保有量
            int HJMonthSYJ = 0;//合计月均市怨件
            DataRow showDR = showDT.NewRow();
            //1.上一年异件数           
            DataRow drYJS = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "异件数"))[0];
            showDR["月份"] = PreYear.ToString() + "年厂异件数";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                hjNum += Convert.ToInt32(drYJS["month" + monthIndex.ToString()]);
                showDR[monthIndex.ToString() + "月"] = drYJS["month" + monthIndex.ToString()];
                hasMonthNum += Convert.ToInt32(drYJS["month" + monthIndex.ToString()]) > 0 ? 1 : 0;
            }
            HJBYL = hjNum;
            showDR["合计"] = hjNum;
            HJMonthBYL = Convert.ToInt32(hjNum / hasMonthNum);
            showDR["月均"] = (hjNum / hasMonthNum).ToString("F0");
            showDT.Rows.Add(showDR);
            //2.上一年交货数
            showDR = showDT.NewRow();
            DataRow drJHS = PreYearShiYuanReportDT.Select(string.Format("SYType='{0}'", "交货数"))[0];
            hjNum = 0;
            hasMonthNum = 0;
            showDR["月份"] = PreYear.ToString() + "年交货物料总类数";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                hjNum += Convert.ToInt32(drJHS["month" + monthIndex.ToString()]);
                showDR[monthIndex.ToString() + "月"] = drJHS["month" + monthIndex.ToString()];
                hasMonthNum += Convert.ToInt32(drJHS["month" + monthIndex.ToString()]) > 0 ? 1 : 0;
            }
            HJSYJ = hjNum;
            showDR["合计"] = hjNum;
            HJMonthSYJ = Convert.ToInt32(hjNum / hasMonthNum);
            showDR["月均"] = (hjNum / hasMonthNum).ToString("F0");
            showDT.Rows.Add(showDR);
            //3.上一年百份比
            showDR = showDT.NewRow();
            showDR["月份"] = PreYear.ToString() + "年百分比";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                showDR[monthIndex.ToString() + "月"] = GetPre(drYJS["month" + monthIndex.ToString()], drJHS["month" + monthIndex.ToString()]) + "%";
            }
            showDR["合计"] = GetPre(HJBYL, HJSYJ) + "%";
            showDR["月均"] = GetPre(HJMonthBYL,HJMonthSYJ) + "%";
            showDT.Rows.Add(showDR);

            //4.本年异件数
            showDR = showDT.NewRow();
            hjNum = 0;
            hasMonthNum = 0;
            drYJS = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "异件数"))[0];
            showDR["月份"] = Year.ToString() + "年厂异件数";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                hjNum += Convert.ToInt32(drYJS["month" + monthIndex.ToString()]);
                showDR[monthIndex.ToString() + "月"] = drYJS["month" + monthIndex.ToString()];
                hasMonthNum += Convert.ToInt32(drYJS["month" + monthIndex.ToString()]) > 0 ? 1 : 0;
            }
            HJBYL = hjNum;
            showDR["合计"] = hjNum;
            HJMonthBYL = Convert.ToInt32(hjNum / hasMonthNum);
            showDR["月均"] = (hjNum / hasMonthNum).ToString("F0");
            showDT.Rows.Add(showDR);
            //5.上一年市怨件
            showDR = showDT.NewRow();
            drJHS = YearShiYuanReportDT.Select(string.Format("SYType='{0}'", "交货数"))[0];
            hjNum = 0;
            hasMonthNum = 0;
            showDR["月份"] = Year.ToString() + "年市怨件数";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                hjNum += Convert.ToInt32(drJHS["month" + monthIndex.ToString()]);
                showDR[monthIndex.ToString() + "月"] = drJHS["month" + monthIndex.ToString()];
                hasMonthNum += Convert.ToInt32(drJHS["month" + monthIndex.ToString()]) > 0 ? 1 : 0;
            }
            HJSYJ = hjNum;
            showDR["合计"] = hjNum;
            HJMonthSYJ = Convert.ToInt32(hjNum / hasMonthNum);
            showDR["月均"] = (hjNum / hasMonthNum).ToString("F0");
            showDT.Rows.Add(showDR);
            //6.年百份比
            showDR = showDT.NewRow();
            showDR["月份"] = Year.ToString() + "年百分比";
            for (int monthIndex = 1; monthIndex <= 12; monthIndex++)
            {
                showDR[monthIndex.ToString() + "月"] = GetPre(drYJS["month" + monthIndex.ToString()], drJHS["month" + monthIndex.ToString()]) + "%";
            }
            showDR["合计"] = GetPre(HJBYL, HJSYJ) + "%";
            showDR["月均"] = GetPre(HJMonthBYL,HJMonthSYJ) + "%";
            showDT.Rows.Add(showDR);

            return showDT;
        }
        #endregion

        #region 报表4
        protected string GetReport4Categories()
        {
            DataTable dtcl = MonthTopReportDT.Select(string.Format("TopType='{0}'", "厂异")).CopyToDataTable();
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            int rowindex = 1;
            foreach (DataRow dr in dtcl.Rows)
            {
                sb.AppendFormat("'{0}'", dr["ChangShang"]);
                if (rowindex != dtcl.Rows.Count)
                {
                    sb.AppendFormat(",");
                }
                rowindex++;
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            return filedstr;
        }

        protected string GetReport4Series()
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sbPre = new StringBuilder();

            int AllShuLiang = 0; //所有市怨件           
            DataTable dtcl = MonthTopReportDT.Select(string.Format("TopType='{0}'", "厂异")).CopyToDataTable();
            AllShuLiang = Convert.ToInt32(dtcl.Compute("sum(ShuLiang)", "1=1"));

            sb.Append("{");
            sb.Append("name: '厂异件数',");
            sb.Append("type: 'column',");
            sb.Append("yAxis: 0,");
            sb.Append("data:[");

            sbPre.Append("{");
            sbPre.Append("name: '百分比',");
            sbPre.Append("type: 'spline',");
            sbPre.Append("yAxis: 1,");
            sbPre.Append("dashStyle: 'shortdot',");
            sbPre.Append("data:[");

            int rowindex = 1;
            foreach (DataRow dr in dtcl.Rows)
            {
                sb.AppendFormat("{0}", dr["ShuLiang"]);
                sbPre.AppendFormat("{0}", GetPre(dr["ShuLiang"], AllShuLiang));
                if (rowindex != dtcl.Rows.Count)
                {
                    sb.AppendFormat(",");
                    sbPre.AppendFormat(",");
                }
                rowindex++;
            }

            sb.Append("]");
            sb.Append("},");

            sbPre.Append("]");
            sbPre.Append("}");

            return sb.ToString() + sbPre.ToString();
        }

        protected DataTable GetReport4ShowData()
        {
            DataTable showDT = new DataTable();
            DataTable dtcl = MonthTopReportDT.Select(string.Format("TopType='{0}'", "厂异")).CopyToDataTable();
            DataColumn showDC = new DataColumn("供应商");
            showDT.Columns.Add(showDC);
            foreach (DataRow dr in dtcl.Rows)
            {
                showDC = new DataColumn(dr["ChangShang"].ToString());
                showDT.Columns.Add(showDC);
            }
            showDC = new DataColumn("合计");
            showDT.Columns.Add(showDC);


            int AllShuLiang = Convert.ToInt32(dtcl.Compute("sum(ShuLiang)", "1=1"));
            DataRow drSYJ = showDT.NewRow();
            DataRow drPRE = showDT.NewRow();
            drSYJ["供应商"] = "厂异件数";
            drPRE["供应商"] = "百分比";

            foreach (DataRow dr in dtcl.Rows)
            {
                drSYJ[dr["ChangShang"].ToString()] = dr["ShuLiang"].ToString();
                drPRE[dr["ChangShang"].ToString()] = GetPre(dr["ShuLiang"], AllShuLiang) + "%";
            }
            drSYJ["合计"] = AllShuLiang;

            showDT.Rows.Add(drSYJ);
            showDT.Rows.Add(drPRE);

            return showDT;
        }
        #endregion
    }
}